/*
 *  AudioElement.h
 *  SoundController0002
 *
 *  Created by jiro on 10/06/28.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#pragma once

#include "SoundElement.h"

namespace sc 
{
	template< class AudioData >
	class AudioElement
	{
	private:

		double startTime;

		const SoundElement< AudioData >* soundElement;

	public:

		AudioElement( double startTime, const SoundElement< AudioData >* const soundElement )
			: startTime( startTime ),
			  soundElement( soundElement )
		{}

		void AdjustDynamics( double adjuster )
		{
			soundElement = SoundElementFactory< AudioData >::CreateWithDynamicsAdjuster( soundElement, adjuster );
		}

		bool operator < ( const AudioElement< AudioData >& rhs ) const
		{
			return startTime < rhs.startTime;
		}

		bool operator > ( const AudioElement< AudioData >& rhs ) const
		{
			return startTime > rhs.startTime;
		}

		bool operator <= ( const AudioElement< AudioData >& rhs ) const
		{
			return startTime <= rhs.startTime;
		}

		bool operator >= ( const AudioElement< AudioData >& rhs ) const
		{
			return startTime >= rhs.startTime;
		}

		double GetStartTime() const
		{
			return startTime;
		}

		double GetEndTime() const
		{
			return startTime + soundElement->GetDuration();
		}
		
		double GetDuration() const
		{
			return soundElement->GetDuration();
		}
		
		double Contains( double time ) const
		{
			if ( GetStartTime() <= time && time <= GetEndTime() )
			{
				return true;
			}
			return false;
		}

		AudioData GetAudioData( double time ) const
		{
			return soundElement->GetAudioData( time - startTime );
		}

		const SoundElement< AudioData >* const GetSoundElement() const
		{
			return soundElement;
		}

	};
	
	typedef float AudioData32;
	
	typedef double AudioData64;

	typedef AudioElement< AudioData32 > AudioElement32;

	typedef AudioElement< AudioData64 > AudioElement64;
}